package com.design.composite.file;

import java.util.ArrayList;
import java.util.List;

// 目录类，实现了文件系统节点接口
class Directory implements FileSystemNode {
    private String name;
    private List<FileSystemNode> nodes = new ArrayList<>();

    public Directory(String name) {
        this.name = name;
    }

    public void addNode(FileSystemNode node) {
        nodes.add(node);
    }

    @Override
    public void display() {
        System.out.println("Directory: " + name);
        for (FileSystemNode node : nodes) {
            node.display();
        }
    }

    @Override
    public long getSize() {
        long totalSize = 0;
        for (FileSystemNode node : nodes) {
            totalSize += node.getSize();
        }
        return totalSize;
    }
}
